<template>
    <a-card :bordered="false">
        <div class="table-operator">
            <!-- <a-button shape="round" size="small" type="primary" icon="cloud-download" @click="excelDownload">导出数据</a-button>  -->
         <!--   <a-button shape="round" size="small" type="primary" icon="cloud-upload" @click="excelUpload">导入数据</a-button>-->
            <a-button  shape="round" size="small" type="primary" icon="plus" @click="add">添加</a-button>
            <a-button  shape="round" size="small" type="primary" icon="plus" @click="cs">测试</a-button>
            <!-- <a-button  shape="round" size="small" type="primary" icon="plus" @click="initAccountNo">生成工号</a-button> -->
        </div>

        <LTable
            ref="empListTable"
            size="middle"
            rowKey="keyId"
            :formAttributes="formAttributes"
            :columns="columns"
            axiosUrl="/SysEmpController/page"
            :showPagination="true"
            :showQueryForm="true"
            :customRow="customRow"
        >
        <template  v-for="column in columnAttributes" :slot="column.field" slot-scope="text, record, index">
            <div :key="column.field">
                <LEditTableColumn rowKey="keyId" :rowKeyValue="rowKeyValue" :record="record" :columnAttribute="column" :index="index" :table="$refs['empListTable']"></LEditTableColumn>
            </div>
        </template>
    </LTable>

    <LExcelDownload :downTable="downTable" ref="LExcelDownload" templateId="1436567506641817602" templateName="人员信息"></LExcelDownload>
    <LExcelUpload :isShowTemplate="true" ref="LExcelUpload" templateId="1436567506641817602" templateName="人员信息"></LExcelUpload>
    </a-card>
</template>

<script>
import LTable from '@/components/lt/LTable'
import request from '@/utils/request'
import {SysMixin} from '@/mixins/SysMixin'
import LExcelUpload from '@/components/lt/LExcelUpload'
import LExcelDownload from '@/components/lt/LExcelDownload'
import defaultSettings from '@/config/defaultSettings'
import LEditTableColumn from '@/components/lt/editTable/LEditTableColumn'
export default {
    name:'empList',
    components:{
       LTable,LExcelUpload,LExcelDownload,LEditTableColumn
    },
    mixins:[SysMixin],
    data(){
        return{
            defaultSettings,
            formAttributes:[
                {field:'empName',label:'人员姓名',component:'input',condition:'like'},
                {field:'accountNo',label:'账号',component:'input',condition:'like'},
                
            ],
            columnAttributes:[
                {field:'empNo',component:'input',required:true,regExp:/^1[3,4,5,6,7,8,9][0-9]\d{8}$/},
                {field:'empName',component:'input',required:true,disabled:false},
                {field:'orgNo',component:'input',required:true},
                {field:'isUse',component:'select',required:true,dictCode:defaultSettings.数据字典.是否},
                
                
            ],
            columns:[
                {
                  
                    title: '序号',
                    dataIndex: '',
                    key:'rowIndex',
                    width:60,
                    align:"center",
                    customRender:function (t,r,index) {
                      return parseInt(index)+1;
                    }
                },
                 {
                    title: '单位',
                    dataIndex: 'orgNo',
                    scopedSlots: { customRender: 'orgNo' },
                    width:160,
                },
                
                {
                    title: '工号',
                    dataIndex: 'empNo',
                    scopedSlots: { customRender: 'empNo' },
                    width:160,
                },
      
                {
                    title: '人员姓名',
                    dataIndex: 'empName',
                    scopedSlots: { customRender: 'empName' },
                    width:160,
                },
                {
                    title:'是否可用',
                    dataIndex:'isUse',
                    scopedSlots: { customRender: 'isUse' },
                    width:160,
                }
             
            ],
            downTable:null,
            rowKeyValue:'',
            
        }
    },
    created(){
       
    },
    methods:{
      excelDownload(){
           this.downTable = this.$refs['empListTable']
            this.$refs['LExcelDownload'].show();
        },
        excelUpload(){
            this.$refs['LExcelUpload'].show();
            
        },
        initAccountNo(){
            let that = this
             request.get('/ScEmpController/initAccountNo',{params:{}}).then((res)=>{
                if (res.success) {
                    that.$message.success(res.message);
                } else {
                    that.$message.warning(res.message);
                }
            })
        },
        cs(){
            this.$refs["empListTable"].localDataSource.filter( item => {
                console.log(item)
            })
           
        },
        add(){

        },
        customRow(record){
            return{
                on:{
                    click:(e)=>{
                       this.rowKeyValue = record.keyId
                       let dataList = this.$refs["empListTable"].localDataSource
                       for(let i=0;i<dataList.length;i++){
                            if(dataList[i].keyId==record.keyId){
                                dataList[i]["editable"] = true
                            }else{
                                dataList[i]["editable"] = false
                            }
                       }
                       
                        console.log(this.$refs["empListTable"].localDataSource)    
                        this.$refs["empListTable"].refreshData()
                        
                    //    console.log(record,e)
                    }
                }
            }
        },
    }
}
</script>